local BaseData = require("data.base.BaseData")
local ChatMsgData = class("ChatMsgData", BaseData)
local schema = {}
schema["senderId"] = {"number", 0}
schema["receiveId"] = {"number", 0}
schema["the_name"] = {"string", ""}
schema["content"] = {"string", ""}
ChatMsgData.schema = schema

function ChatMsgData:ctor()
    ChatMsgData.super.ctor(self)
end

function ChatMsgData:update(message)
    local senderId = rawget(message, "senderId")
    local receiveId = rawget(message, "receiveId")
    local content = rawget(message, "content")
    content = string.gsub(content, "\0", "")
    local name = rawget(message, "name")
    name = string.gsub(name, "\0", "")
    self:setSenderId(senderId)
    self:setReceiveId(receiveId)
    self:setContent(content)
    self:setThe_name(name)
end

function ChatMsgData:getPlayerId()
    local myId = G_UserData:getBase():getId()
    if myId == self:getSenderId() then
        return self:getReceiveId()
    else
        return self:getSenderId()
    end
end

function ChatMsgData:isRight()
    local myId = G_UserData:getBase():getId()
    return myId == self:getSenderId()
end

function ChatMsgData:getName()
    if self:isRight() then
        return G_UserData:getBase():getName()
    else
        return self:getThe_name()
    end
end

return ChatMsgData
